export default {
  functional: true,
  name: 'ItemCell',
  props: {
    context: Object,
    align: String,
    slots: Function | undefined
  },
  render(h, c) {
    const { slots, context, align } = c.props
    if (context.slots && typeof slots !== 'function') {
      throw new Error('yisa: 缺少插槽-' + context.dataIndex)
    }
    const slotScope = {
      scopedSlots: context.slots ? {
        default: (scope) => slots(scope)
      } : context.time && { default: (scope) => h('span', scope.row[context.dataIndex].slice(0, 10)) }
    }

    return (
      <el-table-column
        { ...slotScope }
        { ...{ props: context.config } }
        key={context.dataIndex}
        align={align}
        prop={context.dataIndex}
        label={context.label}
      >
        { c.scopedSlots.default?.() }
      </el-table-column>
    )
  }
}
